/**
 * @Description: UserServiceImpl
 * @Author: Mr.Niu
 * @Date: 2022/9/20 17:22
 */
package com.zhiyou.crud.service.impl;
import com.zhiyou.crud.bean.User;
import com.zhiyou.crud.dao.UserMapper;
import com.zhiyou.crud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    //用户登录
    public User getSelectUser(User user) {
           Example example=new Example(User.class);
           Example.Criteria criteria = example.createCriteria();
           criteria.andEqualTo("uphone",user.getUphone()).
                   orEqualTo("uemail",user.getUemail()).
                   andEqualTo("upassword",user.getUpassword());
        List<User> users = userMapper.selectByExample(example);
       if (users.size()!=0){
           return users.get(0);
       }
       return null;
    }

    @Override
    //用户添加
    public int addUser(User user) {

        return userMapper.insertSelective(user);
    }
}